@model DeathReportManagement.Controllers.AuditStatistics
@{
    ViewData["Title"] = "统计分析";
}

<div class="d-flex justify-content-between align-items-center mb-3">
    <h2>统计分析</h2>
    <a asp-action="Index" class="btn btn-secondary">返回日志</a>
</div>

<!-- 概览统计 -->
<div class="row mb-4">
    <div class="col-md-3">
        <div class="card text-center">
            <div class="card-body">
                <h5 class="card-title text-primary">@Model.TotalReports</h5>
                <p class="card-text">报告总数</p>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card text-center">
            <div class="card-body">
                <h5 class="card-title text-warning">@Model.PendingAuditReports</h5>
                <p class="card-text">待审核</p>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card text-center">
            <div class="card-body">
                <h5 class="card-title text-success">@Model.AuditedReports</h5>
                <p class="card-text">已审核</p>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card text-center">
            <div class="card-body">
                <h5 class="card-title text-info">@Model.MainReportedReports</h5>
                <p class="card-text">主联已上报</p>
            </div>
        </div>
    </div>
</div>

<!-- 时间统计 -->
<div class="row mb-4">
    <div class="col-md-6">
        <div class="card text-center">
            <div class="card-body">
                <h5 class="card-title text-secondary">@Model.TodayCreatedReports</h5>
                <p class="card-text">今日新增</p>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="card text-center">
            <div class="card-body">
                <h5 class="card-title text-secondary">@Model.ThisMonthCreatedReports</h5>
                <p class="card-text">本月新增</p>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <!-- 近7天操作统计 -->
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">近7天操作统计</h6>
            </div>
            <div class="card-body">
                @if (Model.RecentOperations.Any())
                {
                    <div class="table-responsive">
                        <table class="table table-sm">
                            <thead>
                                <tr>
                                    <th>操作类型</th>
                                    <th>次数</th>
                                    <th>比例</th>
                                </tr>
                            </thead>
                            <tbody>
                                @{
                                    var totalOps = Model.RecentOperations.Sum(x => x.Count);
                                }
                                @foreach (var op in Model.RecentOperations)
                                {
                                    var percentage = totalOps > 0 ? (op.Count * 100.0 / totalOps) : 0;
                                    <tr>
                                        <td>@op.Operation</td>
                                        <td>@op.Count</td>
                                        <td>
                                            <div class="progress" style="height: 20px;">
                                                <div class="progress-bar" style="width: @percentage.ToString("F1")%">
                                                    @percentage.ToString("F1")%
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                }
                else
                {
                    <p class="text-muted">近7天内暂无操作记录</p>
                }
            </div>
        </div>
    </div>
    
    <!-- 用户活跃度 -->
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">用户活跃度（近7天）</h6>
            </div>
            <div class="card-body">
                @if (Model.UserActivity.Any())
                {
                    <div class="table-responsive">
                        <table class="table table-sm">
                            <thead>
                                <tr>
                                    <th>用户</th>
                                    <th>操作次数</th>
                                    <th>最后操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var user in Model.UserActivity)
                                {
                                    <tr>
                                        <td>@user.UserName</td>
                                        <td>
                                            <span class="badge bg-primary">@user.OperationCount</span>
                                        </td>
                                        <td>
                                            <small class="text-muted">
                                                @user.LastOperationTime.ToString("MM-dd HH:mm")
                                            </small>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                }
                else
                {
                    <p class="text-muted">近7天内暂无用户操作记录</p>
                }
            </div>
        </div>
    </div>
</div>

<!-- 审核进度 -->
<div class="row mt-4">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">审核进度</h6>
            </div>
            <div class="card-body">
                @{
                    var auditProgress = Model.TotalReports > 0 ? (Model.AuditedReports * 100.0 / Model.TotalReports) : 0;
                    var reportProgress = Model.TotalReports > 0 ? (Model.MainReportedReports * 100.0 / Model.TotalReports) : 0;
                }
                
                <div class="mb-3">
                    <label class="form-label">审核完成率：@auditProgress.ToString("F1")% (@Model.AuditedReports/@Model.TotalReports)</label>
                    <div class="progress">
                        <div class="progress-bar bg-success" style="width: @auditProgress.ToString("F1")%"></div>
                    </div>
                </div>
                
                <div class="mb-3">
                    <label class="form-label">主联上报率：@reportProgress.ToString("F1")% (@Model.MainReportedReports/@Model.TotalReports)</label>
                    <div class="progress">
                        <div class="progress-bar bg-info" style="width: @reportProgress.ToString("F1")%"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>